package com.iSnail.ms.gather.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;

import com.iSnail.ms.util.AppUtil;
import com.iSnail.ms.util.Const;
import com.iSnail.ms.util.I18N;

public class StatusPanel extends JPanel{
	String username = null;
	String msg = null;
	int degree = 88;
	JLabel time = new JLabel(AppUtil.getCurrentTimeDesc());
	JProgressBar progressBar = new JProgressBar();
	JLabel msgLabel = new JLabel();
	
	public StatusPanel(String username,String msg){
		setUsername(username);
		setStatusMsg(msg);
		setBorder(BorderFactory.createLoweredBevelBorder());
		initUI();
	}
	
	public void setStatusMsg(String msg){
		this.msg = msg;
	}
	public void setUsername(String username){
		this.username = username;
	}
	
	public void setDegree(int degree){
		this.degree = degree;
	}

	private void initUI(){
		msgLabel.setText(msg+username);
		//msgLabel.setBorder(BorderFactory.createLoweredBevelBorder());
		
		progressBar.setValue(degree);		
		progressBar.setIndeterminate(false);
		progressBar.setStringPainted(true);
		
		JPanel progress = new JPanel();
		JLabel title = new JLabel(I18N.getString(Const.CURRENT_DEGREE));
		progress.add(title);
		progress.add(progressBar);
		
		JPanel timepanel = new JPanel();
		JLabel currenttime = new JLabel(I18N.getString(Const.SYSTEM_TIME));
		timepanel.add(currenttime);
		timepanel.add(time);
		//timepanel.setBorder(BorderFactory.createLoweredBevelBorder());
		
		setLayout(new GridBagLayout());
		add(msgLabel,new GridBagConstraints(0,0,3,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(0, 3, 0, 0),0,0));
		//add(progress,new GridBagConstraints(1,0,3,1,1,1,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0, 0, 0, 0),0,0));
		add(timepanel,new GridBagConstraints(2,0,3,1,1,1,GridBagConstraints.EAST,GridBagConstraints.NONE,new Insets(0, 0, 0, 0),0,0));
		new Thread(){
			public void run() {
				while(true){
					try {
						Thread.sleep(1000);
						time.setText(AppUtil.getCurrentTimeDesc());
						degree++;
						if( degree>98 ){
							degree = 88 ;
						}
						progressBar.setValue(degree);
						msgLabel.setText(msg+username);
						repaint();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}.start();
	}
}
